/*
 * Copyright (c) 2021 Eshel. 
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *      
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package lib.android.extra;

import android.app.Activity;

import androidx.fragment.app.FragmentActivity;

/**
 * createBy Eshel
 * createTime: 2019/5/27 17:15
 * desc: 为Activity添加额外成员变量使用
 */
public class ExtraDataHelper {

	private static final ExtraDataHelperImpl impl = new ExtraDataHelperImpl();
	private static final ExtraDataHelperSupportImpl supportImpl = new ExtraDataHelperSupportImpl();

	public static void clear(Activity activity, String key){
		if(activity instanceof FragmentActivity){
			supportImpl.clear((FragmentActivity) activity, key);
			return;
		}
		impl.clear(activity, key);
	}

	public static void set(Activity activity, String key, Object value){
		if(activity instanceof FragmentActivity){
			supportImpl.set((FragmentActivity) activity, key, value);
			return;
		}
		impl.set(activity, key, value);
	}

	public static <T> T get(Activity activity, String key, Class<T> type){
		if(activity instanceof FragmentActivity){
			return supportImpl.get((FragmentActivity) activity, key, type);
		}
		return impl.get(activity, key, type);
	}

	static ActivityMemberVarExtSupportFragment getSupportFragment(FragmentActivity activity){
		return supportImpl.getFragment(activity);
	}
}
